<template>
  <div class="view-wrapper">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="订单号：">
          <el-input
            v-model="formInline.relevancyNo"
            placeholder="请输入订单号"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="商户账户名称：">
          <el-select v-model="formInline.region" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="商户账户名称：">
          <el-input
            v-model="formInline.merchantName"
            placeholder="请输入商户账户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="资金流向：">
          <el-select v-model="formInline.fundFlow" placeholder="请选择">
            <el-option
              v-for="item in options3"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付时间：">
          <el-date-picker
            v-model="date"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交易流水号：">
          <el-input
            v-model="formInline.relevancySerialNo"
            placeholder="请输入交易流水号"
          ></el-input>
        </el-form-item>
        <el-form-item label="交易明细类型：">
          <el-select v-model="formInline.billType" placeholder="请选择">
            <el-option
              v-for="item in options2"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <export-excel-button
          title="账单列表"
          action="/merchant/bill/v1/bill/export"
          :params="ExportParams"
        />
      </div>
      <ex-table
        ref="table"
        :loading="loading"
        :table-column="tableColumn"
        :table-data="tableData"
        @pageSizeChange="handleSizeChange"
        @currentPageChange="handleCurrentChange"
      >
        <template v-slot:operate="{ scope }">
          <el-button @click="lookDetail(scope.row)">查看</el-button>
        </template>
      </ex-table>
    </div>
  </div>
</template>
<script>
// components
import { adminGetMerchantBill,adminDict } from "@/api/moneyManagement";
import ExportExcelButton from "@/components/ExportExcelButton/index";
import handlePageMixin from "@/mixins/handlePageMixin";
export default {
  name: "billList",
  components: {
    ExportExcelButton,
  },
  mixins: [handlePageMixin],
  data() {
    return {
      loading: false,
      formInline: {
        relevancyNo: "", //订单号
        relevancySerialNo: "", //关联流水号
        merchantName: "", //商家名称
        fundFlow: "", //资金流向类型（1 流入 2 流出）
        startTime: "", //支付开始时间
        endTime: "", //支付结束
        billType: "", //账单类型（1 用户消费订单 2 提现订单）
      },
      date: [],
      options: [
        {
          value: "0",
          label: "请选择",
        },
        {
          value: "1",
          label: "商家名称1",
        },
        {
          value: "2",
          label: "商家名称2",
        },
      ],
      options2: [],
      options3: [],
      tableData: [],
      tableColumn: [
        { prop: "relevancyNo", label: "交易单号" },
        { prop: "relevancySerialNo", label: "交易流水号" },
        { prop: "transactionTime", label: "交易成功时间" },
        { prop: "merchantName", label: "商户账户名称" },
        { prop: "billTypeDict", label: "交易明细类型" },
        { prop: "fundFlowDict", label: "资金流向" ,width:120},
        { prop: "receivedMoneytxt", label: "应收入（¥）" ,width:120},
        { prop: "practicalReceivedMoneytxt", label: "实际收入（¥）",width:120 },
        { prop: "outflowtxt", label: "应流出（¥）" ,width:120},
        { prop: "actualoutflowtxt", label: "实际流出（¥）",width:120 },
        { prop: "settlementStatusDict", label: "结算状态",width:120 },
        { label: "操作", slot: true, slotName: "operate" },
      ],
    };
  },
  computed: {
    ExportParams() {
      const { id: ticketId } = this;
      const params = {
        ...this.pageOptions,
        ...this.formInline,
        startTime: this.date[0],
        endTime: this.date[1]
      };
      return params;
    },
  },
  mounted() {
    this.getlinkagelist()
    this.getTransactiontype()
    this.getList();
  },
  methods: {
    getlinkagelist() {
      //获取资金流向
      const params = {
        dictType: "fund_flow_type",
      };
      adminDict(params).then((res) => {
        var arr = [
          {
            id: "",
            value: "全部",
          },
        ];
        this.options3 = arr.concat(res.result[0].dictList);
      });
    },
    getTransactiontype() {
      //获取交易明细类型
      const params = {
        dictType: "merchant_bill_type",
      };
      adminDict(params).then((res) => {
        var arr = [
          {
            id: "",
            value: "全部",
          },
        ];
        this.options2 = arr.concat(res.result[0].dictList);
      });
    },
    lookDetail(e) {
      console.log(e);
      this.$router.push({
        path: "/moneyManagement/bill-detail",
        query: { 
          orderId: e.relevancyNo,
          type: e.billType,
        },
      });
    },
    search() {
      //搜索
      console.log(this.formInline);
      this.formInline.startTime = this.date[0]
      this.formInline.endTime = this.date[1]
      this.pageOptions.pageNum = 1
      this.$refs.table.pageOptions.pageNum = 1
      this.getList();
    },
    reset() {
      this.formInline = {};
      // this.formInline.fundFlow = ''
      // this.formInline.billType = ''
      this.date = [];
      this.pageOptions.pageNum = 1
      this.$refs.table.pageOptions.pageNum = 1
      this.getList();
    },
    getList() {
      //联动信息
      const params = {
        ...this.pageOptions,
        ...this.formInline,
      };
      this.loading = true;
      adminGetMerchantBill(params)
        .then((res) => {
          const { total, records } = res.result;
          records.forEach((item) => {
            if (item.fundFlow == 1) {
              item.receivedMoneytxt = "+" + item.receivedMoney;
              item.practicalReceivedMoneytxt = "+" + item.practicalReceivedMoney;
              item.outflowtxt = '-';
              item.actualoutflowtxt = '-'
            } else {
              item.outflowtxt = "-" + item.receivedMoney;
              item.actualoutflowtxt = "-" + item.practicalReceivedMoney;
              item.receivedMoneytxt = '-';
              item.practicalReceivedMoneytxt = '-'
            }
          });
          this.tableData = records;
          this.$refs.table.pageOptions.total = total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>
<style lang="scss">
.el-card-title {
  font-size: 20px;
}
</style>
<style lang="scss" scoped>
.head {
  box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
  background-color: #fff;
  border-radius: 8px;
  //   height: 120px;
  padding: 20px 20px 0;
}
.el-form--inline .el-form-item {
  margin-right: 40px;
}
.listBox {
  box-shadow: 0px 4px 12px 0px rgb(1 41 99 / 6%);
  background-color: #fff;
  border-radius: 8px;
  //   height: 120px;
  padding: 20px 20px;
  margin-top: 10px;
}
.table_list {
  display: flex;
  align-items: center;
  // border: 1px solid #DCDFE6;
  border-radius: 7px;
  width: 220px;
  margin-bottom: 10px;
}
.tableBox {
  width: calc(100% / 3);
  height: 36px;
  text-align: center;
  line-height: 36px;
  color: #303133;
  font-size: 14px;
  border: 1px solid #dcdfe6;
  border-right: 0;
}
.tableBox:first-child {
  border-radius: 7px 0px 0px 7px;
}
.tableBox:last-child {
  border-right: 1px solid #dcdfe6;
  border-radius: 0px 7px 7px 0px;
}
.spchoosetext {
  background-color: #fff4e6;
  color: #ff9300;
  // border: 1px solid #ff9300;
}
.listBox_head {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>
